//
//  DepositsBankInfoCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/17.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "DepositsBankInfoCell.h"

@interface DepositsBankInfoCell()<UITextFieldDelegate>

@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UILabel *titleLB;

@property (nonatomic,strong) UILabel *subTitleLB;

@property (nonatomic,strong) UITextField *bankAccount_TF;

@property (nonatomic,strong) UITextField *bankNo_TF;

@property (nonatomic,strong) UITextField *bankName_TF;

@property (nonatomic,strong) UITextField *bankAddress_TF;

@property (nonatomic,strong) UIView *topLineV;

@property (nonatomic,strong) UIView *lineV;

@property (nonatomic,strong) UIView *secondLineV;

@end

@implementation DepositsBankInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = MainBackColor;
        self.backgroundColor = MainBackColor;
        
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setDeposDict:(NSMutableDictionary *)deposDict{
    _deposDict = deposDict;
    NSString *account = _deposDict[@"account"];
    NSString *cardno = _deposDict[@"cardno"];
    NSString *openBank = _deposDict[@"openbank"];
    NSString *bankAddress = _deposDict[@"bank"];
    self.bankNo_TF.text = cardno;
    self.bankAccount_TF.text = account;
    self.bankName_TF.text = openBank;
    self.bankAddress_TF.text = bankAddress;
}
#pragma mark - UI
-(void)initUI{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.titleLB];
    [self.bgView addSubview:self.subTitleLB];
    [self.bgView addSubview:self.bankAccount_TF];
    [self.bgView addSubview:self.topLineV];
    [self.bgView addSubview:self.bankNo_TF];
    [self.bgView addSubview:self.lineV];
    [self.bgView addSubview:self.bankName_TF];
    [self.bgView addSubview:self.secondLineV];
    [self.bgView addSubview:self.bankAddress_TF];
}
#pragma mark - lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 290)];
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}
- (UILabel *)titleLB{
    if (!_titleLB) {
        _titleLB = [[UILabel alloc] initWithFrame:CGRectMake(14, 24, 90*Width_Scale, 22)];
        _titleLB.text = @"银行卡信息";
        _titleLB.font = FontSetWithWeight(16, 0.3f);
        _titleLB.textAlignment = NSTextAlignmentLeft;
        _titleLB.textColor = MainBlackTextColor;
    }
    return _titleLB;
}
- (UILabel *)subTitleLB{
    if (!_subTitleLB) {
        _subTitleLB = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLB.right+5, self.titleLB.top+2, 80*Width_Scale, 18)];
        _subTitleLB.text = @"(全部必填)";
        _subTitleLB.font = FontSet(13);
        _subTitleLB.textAlignment = NSTextAlignmentLeft;
        _subTitleLB.textColor = MainGrayTextColor;
    }
    return _subTitleLB;
}
- (UITextField *)bankAccount_TF{
    if (!_bankAccount_TF) {
        _bankAccount_TF = [[UITextField alloc] initWithFrame:CGRectMake(14, self.titleLB.bottom+20, ScreenWidth-28, 30)];
        _bankAccount_TF.textColor = MainBlackTextColor;
        _bankAccount_TF.font = FontSet(15);
        _bankAccount_TF.placeholder = @"比如张三";
        _bankAccount_TF.textAlignment = NSTextAlignmentRight;
        _bankAccount_TF.leftView = [self leftViewWithTitle:@"开户行账户"];
        _bankAccount_TF.leftViewMode = UITextFieldViewModeAlways;
        _bankAccount_TF.delegate = self;
    }
    return _bankAccount_TF;
}

- (UIView *)topLineV{
    if (!_topLineV) {
        _topLineV = [[UIView alloc] initWithFrame:CGRectMake(10, self.bankAccount_TF.bottom+15, ScreenWidth-20, 1)];
        _topLineV.backgroundColor = MainPureColor(239);
    }
    return _topLineV;
}

- (UITextField *)bankNo_TF{
    if (!_bankNo_TF) {
        _bankNo_TF = [[UITextField alloc] initWithFrame:CGRectMake(14, self.topLineV.bottom+15, ScreenWidth-28, 30)];
        _bankNo_TF.textColor = MainBlackTextColor;
        _bankNo_TF.font = FontSet(15);
        _bankNo_TF.placeholder = @"请输入银行卡卡号";
        _bankNo_TF.keyboardType = UIKeyboardTypeNumberPad;
        _bankNo_TF.textAlignment = NSTextAlignmentRight;
        _bankNo_TF.leftView = [self leftViewWithTitle:@"银行卡卡号"];
        _bankNo_TF.leftViewMode = UITextFieldViewModeAlways;
        _bankNo_TF.delegate = self;
    }
    return _bankNo_TF;
}
- (UIView *)lineV{
    if (!_lineV) {
        _lineV = [[UIView alloc] initWithFrame:CGRectMake(10, self.bankNo_TF.bottom+15, ScreenWidth-20, 1)];
        _lineV.backgroundColor = MainPureColor(239);
    }
    return _lineV;
}
- (UITextField *)bankName_TF{
    if (!_bankName_TF) {
        _bankName_TF = [[UITextField alloc] initWithFrame:CGRectMake(14, self.lineV.bottom+15, ScreenWidth-28, 30)];
        _bankName_TF.textColor = MainBlackTextColor;
        _bankName_TF.font = FontSet(15);
        _bankName_TF.placeholder = @"请输入开户银行";
        _bankName_TF.textAlignment = NSTextAlignmentRight;
        _bankName_TF.leftView = [self leftViewWithTitle:@"开户行"];
        _bankName_TF.leftViewMode = UITextFieldViewModeAlways;
        _bankName_TF.delegate = self;
    }
    return _bankName_TF;
}
- (UIView *)secondLineV{
    if (!_secondLineV) {
        _secondLineV = [[UIView alloc] initWithFrame:CGRectMake(10, self.bankName_TF.bottom+15, ScreenWidth-20, 1)];
        _secondLineV.backgroundColor = MainPureColor(239);
    }
    return _secondLineV;
}
- (UITextField *)bankAddress_TF{
    if (!_bankAddress_TF) {
        _bankAddress_TF = [[UITextField alloc] initWithFrame:CGRectMake(14, self.secondLineV.bottom+15, ScreenWidth-28, 30)];
        _bankAddress_TF.textColor = MainBlackTextColor;
        _bankAddress_TF.font = FontSet(15);
        _bankAddress_TF.placeholder = @"请输入开户银行地址";
        _bankAddress_TF.textAlignment = NSTextAlignmentRight;
        _bankAddress_TF.leftView = [self leftViewWithTitle:@"开户行地址"];
        _bankAddress_TF.leftViewMode = UITextFieldViewModeAlways;
        _bankAddress_TF.delegate = self;
    }
    return _bankAddress_TF;
}
//uitextfield  左侧view
-(UIView *)leftViewWithTitle:(NSString *)title{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
    UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 80, 20)];
    lb.text = title;
    lb.textAlignment = NSTextAlignmentLeft;
    lb.textColor = UIColor.blackColor;
    lb.font = FontSet(15);
    [view addSubview:lb];
    return view;
}

#pragma mark - UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == self.bankAccount_TF) {
        self.deposDict[@"account"] = textField.text;
    }else if (textField == self.bankNo_TF) {
        self.deposDict[@"cardno"] = textField.text;
    }else if (textField == self.bankName_TF){
        self.deposDict[@"openbank"] = textField.text;
    }else{
        self.deposDict[@"bank"] = textField.text;
    }
    if (self.updateDeposBlock) {
        self.updateDeposBlock(self.deposDict);
    }
}





@end
